package kr.hkit.powerjava.chapter12.submit;

import java.util.Arrays;
import java.util.Comparator;

class Person implements Comparable {
	String name;
	int height;

	public Person(String name, int height) {
		this.name = name;
		this.height = height;
	}

	public String getName() {
		return name;
	}

	public int getHeight() {
		return height;
	}

	@Override
	public double compareTo(Object other) {
		return (this.height - ((Person) other).height);
	}

	@Override
	public String toString() {
		return "[이름:" + name + ", 키:" + height + "cm]";
	}

	public static void arrPrn(Person[] arr) {
		for (Person p : arr) {
			System.out.print(p + " ");
		}
		System.out.println();
	}
	
	
	public static void main(String[] args) {

		Person[] arr = new Person[3];
		arr[0] = new Person("홍길동", 180);
		arr[1] = new Person("고길동", 160);
		arr[2] = new Person("김철수", 175);

		Comparator<Person> getMaximum = new Comparator<Person>() {
			@Override
			public int compare(Person o1, Person o2) {
				return (o1.getHeight() - (((Person) o2).getHeight()));
			}
		};

		Arrays.sort(arr, getMaximum);
		arrPrn(arr);
	}
}
